package com.hdjk.view.network;

import com.hdjk.view.callback.CallBackListener;
import com.hdjk.view.callback.GetWalletFundCallBack;
import com.hdjk.view.callback.GetWalletHistoricalDataCallBack;
import com.hdjk.view.callback.GetWalletHoldingsCallBack;
import com.hdjk.view.callback.GetWalletProfitListCallBack;
import com.hdjk.view.callback.GetWalletTransactionListCallBack;
import com.hdjk.view.callback.RechargeWalletCallback;
import com.hdjk.view.callback.TakeWalletCallback;
import com.hdjk.view.config.Constant;
import com.lst.projectlib.entity.Msg;
import com.zhy.http.okhttp.OkHttpUtils;

import okhttp3.Call;
import okhttp3.MediaType;

/**
 * Created by sxy on 2018/1/2.
 */

public class WalletNetWork {
    /**
     * 获取现金钱包资产
     * @param jsonInfo
     * @param listener
     */
    public static void getWalletHoldings(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_WALLET_HOLDINGS)
                    .addHeader("Authorization","Bearer "+token)
                    .addParams("paramList", jsonInfo)
                    .build()
                    .execute(new GetWalletHoldingsCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }


    /**
     * 现金钱包充值
     * @param jsonInfo
     * @param listener
     */
    public static void rechargeWallet(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.postString().url(Constant.URL_RECHARGE_WALLET)
                    .addHeader("Authorization","Bearer "+token)
                    .mediaType(MediaType.parse(Constant.json_format))
                    .content(jsonInfo)
                    .build()
                    .execute(new RechargeWalletCallback() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 现金钱包提现
     * @param jsonInfo
     * @param listener
     */
    public static void takeWallet(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.post().url(Constant.URL_TAKE_WALLET+ "&paramList=" + jsonInfo)
                    .addHeader("Authorization","Bearer "+token)
                    .build()
                    .execute(new TakeWalletCallback() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取现金钱包交易记录
     * @param jsonInfo
     * @param listener
     */
    public static void getWalletTransactionList(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_WALLET_TRANSACTION_LIST)
                    .addHeader("Authorization","Bearer "+token)
                    .addParams("paramList", jsonInfo)
                    .build()
                    .execute(new GetWalletTransactionListCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取现金钱包收益记录
     * @param jsonInfo
     * @param listener
     */
    public static void getWalletProfitList(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_WALLET_PROFIT_LIST)
                    .addHeader("Authorization","Bearer "+token)
                    .addParams("paramList", jsonInfo)
                    .build()
                    .execute(new GetWalletProfitListCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取现金钱包基金的历史数据
     * @param jsonInfo
     * @param listener
     */
    public static void getWalletHistoricalData(String token,String jsonInfo, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_WALLET_HISTORICAL_DATA)
                    .addHeader("Authorization","Bearer "+token)
                    .addParams("paramList", jsonInfo)
                    .build()
                    .execute(new GetWalletHistoricalDataCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }

    /**
     * 获取现金钱包基金的详情
     * @param listener
     */
    public static void getWalletFund(String token, final CallBackListener listener) {
        try {
            OkHttpUtils.get().url(Constant.URL_GET_WALLET_FUND)
                    .addHeader("Authorization","Bearer "+token)
                    .build()
                    .execute(new GetWalletFundCallBack() {
                        @Override
                        public void onResponse(Msg msg, int arg1) {
                            if (listener != null) {
                                listener.onCallBackCompleted(msg);
                            }
                        }

                        @Override
                        public void onError(Call arg0, Exception arg1, int arg2) {
                            super.onError(arg0, arg1, arg2);
                            if (listener != null) {
                                Msg msg = new Msg();
                                msg.setMsg(arg1.toString());
                                listener.onCallBackCompleted(msg);
                            }
                        }
                    });
        } catch (Exception e) {
        }
    }
}
